package com.lg.cms.service.impl;

import com.lg.cms.entity.Role;
import com.lg.cms.entity.SuperUser;
import com.lg.cms.mapper.RoleMapper;
import com.lg.cms.mapper.SuperUserMapper;
import com.lg.cms.service.SuperUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lg.cms.vo.admin.SuperUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 超级用户（管理员）表 服务实现类
 * </p>
 *
 * @author lg
 * @since 2020-09-21
 */
@Service
public class SuperUserServiceImpl extends ServiceImpl<SuperUserMapper, SuperUser> implements SuperUserService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    public SuperUserVO toSuperUserVO(SuperUser superUser) {
        SuperUserVO vo = new SuperUserVO();
        vo.setId(superUser.getId());
        vo.setUsername(superUser.getUsername());
        vo.setPassword(superUser.getPassword());
        vo.setNickname(superUser.getNickname());
        vo.setRoleId(superUser.getRoleId());
        vo.setCreateTime(superUser.getCreateTime());
        vo.setStringId(superUser.getId().toString());
        Role role = roleMapper.selectById(vo.getRoleId());
        if(role != null){
            vo.setRoleName(role.getName());
        }
        return vo;
    }

//    @Override
//    public Map<Integer, String> getRoleMap() {
//        Map<Integer, String> map = new HashMap<>();
//        roleMapper.selectList(null).forEach(v -> map.put(v.getId(), v.getName()));
//        return map;
//    }

}
